package com.ndp.fb.rdb.db.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.rdb.api.AdPublishConditionDetailRdbService;
import com.ndp.fb.rdb.db.DaoTemplate;
import com.ndp.fb.rdb.db.impl.mapper.DefaultRowMapper;
import com.ndp.fb.rdb.model.adpublishcondition.AdPublishConditionDetail;

/**
 * Created by jacky.cheng on 2016/3/3.
 */
@Service
public class AdPublishConditionDetailRdbServiceImpl extends DaoTemplate implements AdPublishConditionDetailRdbService {
    @Override
    public AdPublishConditionDetail findDetailById(String userId, Long connObjId, Long prodCfgId) {
        String sql = "SELECT * FROM ad_publish_condition_detail WHERE condition_id IN (SELECT id FROM ad_publish_condition t WHERE user_id =? AND connection_object_id = ? AND product_configuration_id = ?)";
        return findOne(sql, new Object[]{userId, connObjId, prodCfgId}, DefaultRowMapper.autoRowMapper(AdPublishConditionDetail.class));
    }

    @Override
    public AdPublishConditionDetail findDetailByConditionId(Long conditionId) {
        String sql = "SELECT * FROM ad_publish_condition_detail WHERE condition_id = ? ";
        return findOne(sql, new Object[]{conditionId}, DefaultRowMapper.autoRowMapper(AdPublishConditionDetail.class));
    }
}
